目录

  1. 互动直播方法介绍 MRTCInteractiveClient

  2. 代理方法介绍 MRTCInteractiveClientRoomDelegate

  3. 设置 MRTCSetting

  4. 错误信息 MRTCError

互动直播方法介绍 MRTCInteractiveClient

/*
作用:初始化互动直播类
host:主机地址
setting:本地推流设置
renderer:渲染本地推流画面的view
*/
- (instancetype)initWithHost:(NSString *)host setting:(MRTCSetting *)setting renderer:(UIView *)renderer;

/*
作用:加入互动直播房间
channel:频道id
role:加入房间作为的角色,主持人为main,嘉宾为1、2、3...等数字编号
password:房间密码,主持人和嘉宾的密码不同
delegate:MRTCInteractiveClientRoomDelegate,会有加入房间后嘉宾加入,嘉宾离开,错误等回调
*/
- (void)joinWithChannel:(NSString *)channel role:(NSString *)role password:(NSString *)password delegate:(id<MRTCInteractiveClientRoomDelegate>)delegate;

/*
作用:离开房间,销毁资源
*/
- (void)leave;

/*
作用:播放指定角色的流
role:角色名,例如:main、1、2、3等
view:用于渲染该角色流的view
*/
- (void)playClientWithRole:(NSString *)role renderView:(UIView *)view;

/*
作用:停止播放指定角色的流
role:角色名,例如:main、1、2、3等
*/
- (void)stopClientWithRole:(NSString *)role;

/*
作用:开关本地视频推流,关闭后房间其他人将看不到您的画面
enable: YES:开 NO:关
*/
- (void)enableLocalVideo:(BOOL)enable;

/*
作用:开关本地音频推流,关闭后房间其他人将看不到您的声音
作用:开关本地音频推流,
enable: YES:开 NO:关
*/
- (void)enableLocalAudio:(BOOL)enable;

/*
作用:开关远端音频推流,关闭后房间其他人的声音将听不到
作用:开关本地音频推流,
enable: YES:开 NO:关
*/
- (void)enableRemoteAudio:(BOOL)enable;

/*
作用:切换本地摄像头
*/
- (void)switchCamera;

/*
作用获取本地推流实时信息
视频编码器 key:videoCodec
视频实时码率 key:videoBitrate
视频实时丢包率 key:videoPacketsLostRate

音频编码器 key:audioCodec
音频实时码率 key:audioBitrate
音频实时丢包率 key:audioPacketsLostRate
*/
- (void)getHostStats:(void(^)(NSDictionary *stats))completion;

代理方法介绍 MRTCInteractiveClientRoomDelegate

/*
作用:互动直播状态改变时会调用,手动调用leave方法不会触发此回调
client:互动直播实例
state:新状态
*/
- (void)MRTCInteractiveClient:(MRTCInteractiveClient *)client stateChanged:(MRTCInteractiveClientState)state;

/*
作用:当调用加入房间接口之后,如果加入房间成功就会回调此方法
client:互动直播实例
roleArray:已经在房间中的其他角色,您可以在回调中遍历此数组调用播放指定角色接口
*/
- (void)MRTCInteractiveClient:(MRTCInteractiveClient *)client joinSuccess:(NSArray<NSString *> *)roleArray;

/*
作用:当调用加入房间接口之后,如果加入房间失败就会回调此方法
client:互动直播实例
error:错误信息
*/
- (void)MRTCInteractiveClient:(MRTCInteractiveClient *)client joinFailed:(MRTCError *)error;

/*
作用:加入房间成功后,如果有新的角色加入房间将会回调此方法
client:互动直播实例
roleArray:新加入的角色数组,您可以在回调中遍历此数组调用播放指定角色接口
*/
- (void)MRTCInteractiveClient:(MRTCInteractiveClient *)client onJoinRoles:(NSArray<NSString *> *)roleArray;

/*
作用:加入房间成功后,如果有角色离开房间将会回调此方法
client:互动直播实例
roleArray:离开的角色数组,您可以在回调用遍历此数组移除对应的图渲染视
*/
- (void)MRTCInteractiveClient:(MRTCInteractiveClient *)client onLeaveRoles:(NSArray<NSString *> *)roleArray;

/*
作用:加入房间成功后,播放其他角色成功时将会回调此方法
client:互动直播实例
role:播放的角色
*/
- (void)MRTCInteractiveClient:(MRTCInteractiveClient *)client playRoleSuccess:(NSString *)role;

/*
作用:加入房间成功后,播放其他角色失败时将会回调此方法
client:互动直播实例
role:播放的角色
error:错误信息
*/
- (void)MRTCInteractiveClient:(MRTCInteractiveClient *)client playRole:(NSString *)role failure:(MRTCError *)error;

/*
作用:加入房间成功后的错误回调
client:互动直播实例
error:错误信息
*/
- (void)MRTCInteractiveClient:(MRTCInteractiveClient *)client onError:(MRTCError *)error;

设置 MRTCSetting

您可以使用MRTCSetting配置推流参数,每一个参数都有默认值,也可以从MRTCSetting中获取机器支持的配置。

  • 默认配置
    在需要使用推流器的ViewController中引用头文件#import <MRTC/MRTCSetting.h>,示例代码如下:

      MRTCSetting *setting = [[MRTCSetting alloc]init];
    
  • 自定义配置

    • 获取支持的编解码器

        NSArray<MRTCCodec *> *supportCodecs = [MRTCSetting supportVideoCodec];
      
    • 获取支持的分辨率(注:分辨率格式为 宽x高)

        NSArray<NSString *> *supportResolutions = [MRTCSetting supportVideoResolutions];
      
    • 获取支持的fps范围

        MRTCFpsRange *fpsRange = [MRTCSetting supportFPSRange];
        NSUInteger min = fpsRange.minFps;//支持的最小fps
        NSUInteger max = fpsRange.maxFps;//支持的最大fps
      
    • 构造自定义配置

        MRTCSetting *customSetting = [[MRTCSetting alloc]initWithVideoCodec:supportCodecs.firstObject videoResolution:@"1280x720" maxBitRate:1800 fps:25 useFrontCamera:YES];
      

设置为自定配置时,您需要自己定义偏好编解码器、视频分辨率、最大码率、帧率、前后摄像头。

自定义配置建议参数:

分辨率 帧率 码率
360p 25 350
480p 25 600
540p 25 1000
720p 25 1500
360p 30 400
480p 30 750
540p 30 1200
720p 30 1800

注:码率估算公式:(0.0000782*视频宽*视频高*帧率)

错误信息 MRTCError

错误码 错误含义
1600 Create new client error
1601 Client Not exist
1602 Stream already exist
1603 Stream not exist
1604 Stream server unavailable
1605 Get Mrtc server error
1606 Play failed
1607 Set play answer failed
1608 Create stream error
1609 Remote create offer error
1610 Set configuration error
1611 Json error
1612 Send message error
1613 Close PeerConnection error
1614 Set candidate error
1615 Keepalive Timeout
1616 Stream have been closed
1617 Websocket have been closed by server
2000 AudioSession Config failed
2001 Priview is nil
2002 URL wrong
2003 Signaling json init error
2004 Signaling json parse error
2005 Ice connect failed
2006 Wrong video resolution setting
2007 No valid formats for device
2008 Capture error
2009 Local create offer error
2010 Set local description error
2011 Local create answer error
2012 Set remote description error
2013 Socket connect faild
2014 MRTC pusher socket disconnect
2015 MRTC puller socket disconnect
2016 MRTC interactive socket disconnect
2017 Role out of bounds
2018 Wrong video resolution format

results matching ""

    No results matching ""